﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; using Montana.Entidades;

namespace Montana
{
    public partial class MaskCustom : MaskedTextBox
    {
        public MaskCustom()
        {
            InitializeComponent();

            this.BackColor = ControlesCustomConfig.GetColorFondo();
            this.ForeColor = ControlesCustomConfig.GetColorLetra();
        }

        bool manejarFoco = true;
        public bool ManejarFoco
        {
            get { return manejarFoco; }
            set { manejarFoco = value; }
        }

        delegate void SetFocoDelegate();

        private void MaskCustom_Enter(object sender, EventArgs e)
        {
            this.BackColor = ControlesCustomConfig.GetColorSelFondo();
            this.ForeColor = ControlesCustomConfig.GetColorSelLetra();

            this.BeginInvoke(new SetFocoDelegate(SetFoco));
        }

        private void SetFoco()
        {
            this.SelectAll();
        }

        private void MaskCustom_Leave(object sender, EventArgs e)
        {
            this.BackColor = ControlesCustomConfig.GetColorFondo();
            this.ForeColor = ControlesCustomConfig.GetColorLetra();
        }

        private void MaskCustom_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13 && ManejarFoco)
            {
                SendKeys.Send("{tab}");
                e.Handled = true;
            }
        }          
    }
}
